package com.yuke.cloud.service.wmc.job;

import com.yuke.cloud.service.wmc.entity.WmsStorage;
import com.yuke.cloud.service.wmc.service.WmsStorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yuke-mall </br> </p>
 * <p>com.yuke.cloud.service.wmc.job Description TODO </br> </p>
 * @Author wg
 * @Date   2019/10/19 14:06
 */
@Component
@Slf4j
@EnableScheduling
public class storageQuartz
{
    @Autowired
    WmsStorageService wmsStorageService;
    /**
     * 店铺线上库存预订划拨定时任务
     */
    //@Scheduled(cron = "0 0 3 * * ?")  // 每天凌晨3点进行
    public void wmcStorageAdd() {
        System.out.println("增加库存,所有的水都保持200以上的库存");
        Example example = new Example(WmsStorage.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("warehouseId",6L);
        criteria.andEqualTo("isEnable",1);

        List<Long> list = new ArrayList<>();
        list.add(172290736401416192L); //饮用水categoryId
        list.add(172291014664126464L); //碳酸饮料
        list.add(172291045676810240L); //茶饮料
        list.add(217333359373451264L); //果汁
        list.add(219470918530629632L); //功能饮料
        list.add(224849869285359616L); //奶制品
        list.add(235703950904131584L); // 咖啡饮品
        criteria.andIn("categoryId",list);
        List<Long> list2 = new ArrayList<>();
        list2.add(253811306787504128L); //安慕希
        list2.add(253818557573103616L); //蒙牛酸酸乳
        list2.add(279575450820018176L); //莫斯利安
        list2.add(279610137441468416L); //特仑苏
        list2.add(279610652250341376L); //纯甄
        list2.add(279615811374284800L); //蒙牛真果粒
        list2.add(282836246882680832L); //蒙牛纯牛奶
        list2.add(282868831050530816L); //蒙牛早餐奶
        criteria.andNotIn("productId",list2);

        List<WmsStorage> storageList = wmsStorageService.selectByExample(example);

        if (storageList!=null && storageList.size()>0) {
            for (WmsStorage item : storageList) {
               if (item.getNumber()-item.getLockNumber() < 200) {
                   item.setNumber(item.getLockNumber()+300);
                   wmsStorageService.update(item);
                }

            }
        }

    }
}
